const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  mode: 'none',
  entry: {
    index: './src/index.js',
    album: './src/album.js',
  },
  output: {
    // 使用[name]占位符，动态输出文件名
    // [name]最终替换为入口的名称，即entry的key
    filename: '[name].bundle.js',
  },
  optimization: {
    splitChunks: {
      // all 表示将所有的公共模块都提取到单独的bundle当中
      chunks: 'all'
    }
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: './src/index.html',
      chunks: ['index'],
    }),
    new HtmlWebpackPlugin({
      filename: 'album.html',
      template: './src/album.html',
      chunks: ['album'],
    }),
  ],
}
